package com.alibaba.csp.sentinel.dashboard.rule.nacos.flow;

import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.dashboard.rule.DynamicRulePublisher;
import com.alibaba.csp.sentinel.dashboard.rule.nacos.NacosConfigUtil;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.util.AssertUtil;
import com.alibaba.nacos.api.config.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangtengfei
 * @date 2021/6/11 10:05
 */
@Component("gatewayFlowRuleNacosPublisher")
public class GatewayFlowRuleNacosPublisher {//implements DynamicRulePublisher<List<GatewayFlowRuleEntity>> {

//    @Autowired
//    private ConfigService configService;
//    @Autowired
//    private Converter<List<GatewayFlowRuleEntity>, String> converter;
//
//    @Override
//    public void publish(String app, List<GatewayFlowRuleEntity> rules) throws Exception {
//        AssertUtil.notEmpty(app, "app name cannot be empty");
//        if (rules == null) {
//            return;
//        }
//        List<GatewayFlowRule> gatewayFlowRuleList = new ArrayList<>();
//        for (GatewayFlowRuleEntity rule : rules) {
//            gatewayFlowRuleList.add(rule.toGatewayFlowRule());
//        }
//        configService.publishConfig(app + NacosConfigUtil.FLOW_DATA_ID_POSTFIX,
//                NacosConfigUtil.GROUP_ID, converter.convert(gatewayFlowRuleList));
//    }
}
